import Image from 'next/image'
import Header from '@/components/home/header'
import header1 from '@/assets/images/header1.png'
import header2 from '@/assets/images/header2.png'
import { useStores } from '@/store'
import { useEffect } from 'react'
import { useRouter } from 'next/router'
import { copyText, deviceDecide, downImageUrl } from '@/utils/domTool'
import { Toast } from 'antd-mobile'
import wxSdk from '@/utils/weixin'
export default function Finish() {
    const store = useStores()
    const router = useRouter()

    useEffect(() => {
        if (store.active.reqImage.is_synthesis == '') {
            router.push({ pathname: '/headshot', query: { ...router.query } })
        }
        store.active.cannalPolling();
    }, [])
    const isWechatStatus =
        deviceDecide.isWechat() || deviceDecide.isWechatProgram()
    return (
        <div className='w-full h-full min-h-r66.7 '>
            <Header cb={() => { router.back() }} headerColor='bg-FFE5E5' headerText={'AI生成情侣头像'}></Header>
            <div className='m-r1.5 text-center '>
                <span className=' block text-r1.8 text-black mb-r1.0 font-bold'>生成成功</span>
                <span className=' block text-r1.6 text-black mb-r1.0 font-normal'>分享头像最多可获得30点AI点数</span>
            </div>
            <div className='h-auto w-full pl-r0.7'>
                <div className='w-r16.5 h-r19.0 inline-block bg-white rounded-2xl m-r0.8 text-center '>
                    <img className=' w-r14.0 h-r14.0 rounded-lg  m-r1.2' src={store.active.resCheck.length > 0 && store.active.resCheck[0].files.length > 0 ? store.active.resCheck[0].files[0].preview : ''} alt={''}></img>
                    <div onClick={() => {
                        const url = '<a href="weixin://wxpay/bizpayurl?appid=wx****&productid=xxx&timestamp=xxx&noncestr=xxx&sign=xxx">跳转小程序</a>'
                        if (store.active.resCheck.length > 0 && store.active.resCheck[0].files.length > 0) {
                            wx.miniProgram.navigateTo({
                                url: `/pages/webView/saveImg?src=${btoa(store.active.resCheck[0].files[0].preview)}`,
                                success: function () { }
                            });
                         //   downImageUrl(store.active.resCheck[0].preview, 'pic1')
                        }

                    }} className='block text-center text-r1.6 font-bold  -mt-r0.5'>下载头像</div>
                </div>
                <div className='w-r16.5 h-r19.0 inline-block bg-white rounded-2xl m-r0.8 text-center'>
                    <img className=' w-r14.0 h-r14.0  rounded-lg m-r1.2' src={store.active.resCheck.length > 1 && store.active.resCheck[1].files.length > 0 ? store.active.resCheck[1].files[0].preview : ''} alt={''}></img>
                    <div className='block text-center text-r1.6 font-bold -mt-r0.5' onClick={() => {
                        if (store.active.resCheck.length > 0 && store.active.resCheck[1].files.length > 0) {
                            wx.miniProgram.navigateTo({
                                url: `/pages/webView/saveImg?src=${btoa(store.active.resCheck[1].files[0].preview)}`,
                                success: function () { }
                            });
                          //  downImageUrl(store.active.resCheck[1].preview, 'pic1')
                        }
                    }}>下载头像</div>
                </div>
            </div>
            <div className=' mt-r1.5 w-full inline-block'>
                <span onClick={() => {
                    if (store.active.resCheck.length == 2) {
                        const id = store.active.resCheck[0].id + ',' + store.active.resCheck[1].id
                        wx.miniProgram.getEnv(function (res) {

                            wx.miniProgram.navigateTo({
                                url: `/pages/webView/share?id=${btoa(id)}`,
                                success: function () { }
                            });
                        })
                        // 发送消息给小程序SSSSSSS 

                        //  wxSdk.wxShare({title:'AI生成情侣头像',desc:'AI生成情侣头像',link:document.location.origin+'/share?id='+btoa(id),imgUrl:'//js.tuguaishou.com/ips_ai_home/mobile/_next/static/media/bg1.5fb19e86.png'},()=>{Toast.show('分享失败')})
                    } else {
                        Toast.show('未生成成功，请重新生成')
                    }

                }} className=' block relative w-r34.5 h-r4.5 leading-r4.5 text-r1.6 rounded-3xl  text-white cursor-pointer  bg-gradient-to-r from-FF4747 to-FF7070   text-center left-1/2 -translate-x-1/2 mb-r1.5 '>去分享</span>
                {/* <a href={`weixin://dl/business/?appid=${store.loingInfo.wexParam.appId}&amp;t=webview&amp;url=${encodeURIComponent('/pages/webView/index?p=headshot')}`} className=' block relative w-r34.5 h-r4.5 leading-r4.5 text-r1.6 rounded-3xl  text-white cursor-pointer  bg-gradient-to-r from-FF4747 to-FF7070   text-center left-1/2 -translate-x-1/2 mb-r1.5 '>分享给微信好友</a> */}
                <span onClick={() => {
                    if (store.active.resCheck.length == 2) {
                        // const id = store.active.resCheck[0].id + ',' + store.active.resCheck[1].id
                        copyText('#小程序://图怪兽/4uJBRMS6jaOr73w')
                        Toast.show('复制成功')
                    }

                }} className=' block relative  w-r34.5 h-r4.5 leading-r4.5  text-r1.6 rounded-3xl   cursor-pointer bg-white  text-center left-1/2 -translate-x-1/2 '>复制分享链接</span>
            </div>

        </div>
    )
}


